package com.symaster.backups.util;

import com.symaster.common.swing.style.Style;
import com.symaster.common.swing.util.SwingUtil;

import javax.swing.*;
import java.awt.*;

/**
 * @author yinmiao
 * @version 2023-04-14 10:12
 */
public class MenuBarUtil {

    public static JMenuBar createJMenuBar() {
        JMenuBar menuBar = new JMenuBar();
        menuBar.setBackground(new Color(242, 242, 242));
        Style.setBorder(1, menuBar);

        JMenu fileMenu = new JMenu("文件");
        menuBar.add(fileMenu);

        JMenuItem addCardItem = new JMenuItem("添加新内容");
        JMenuItem settingItem = new JMenuItem("首选项");
        // addCardItem.addActionListener(e -> openDialog("SelectFolderDialog"));
        // settingItem.addActionListener(e -> openDialog("SettingsDialog"));
        fileMenu.add(addCardItem);
        fileMenu.add(settingItem);

        JMenu viewMenu = new JMenu("视图");
        menuBar.add(viewMenu);

        JMenuItem viewMenu_card = new JMenuItem("卡片");
        // viewMenu_card.addActionListener(e -> changeViewType("card"));
        JMenuItem viewMenu_strip = new JMenuItem("条形");
        // viewMenu_strip.addActionListener(e -> changeViewType("strip"));
        viewMenu.add(viewMenu_card);
        viewMenu.add(viewMenu_strip);

        return menuBar;
    }

    public static TrayIcon createTrayIcon(Dimension trayIconSize) {
        PopupMenu pop = new PopupMenu();
        MenuItem item1 = new MenuItem("Open ToolBox");
        // item1.addActionListener(e -> BeanFactory.get(MainFrame.class).open());
        pop.add(item1);

        MenuItem item = new MenuItem("Quit ToolBox");
        item.addActionListener((e) -> System.exit(0));
        pop.add(item);

        return new TrayIcon(SwingUtil.loadIcon("icon.png", trayIconSize.width, trayIconSize.height).getImage(), "ToolBox", pop);
    }
}
